package com.fieldchain.ex.fa100.ui.money.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.bean.RecListBean;
import com.bumptech.glide.Glide;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/13
 */
public class RecListAdapter extends RecyclerView.Adapter<RecListAdapter.ViewHolder> {
    private Context mContext;
    private int c1=Color.parseColor("#FF6C78A0");
    private int c2=Color.parseColor("#FFDC3950");

    private String[]status=new String[]{"充值成功","提币申请","提币成功","提币失败"};
    public RecListAdapter(Context mContext) {
        this.mContext = mContext;
    }
    private List<RecListBean> list = new ArrayList<>();
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    public void setData(List<RecListBean> list) {
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_reclist,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        RecListBean bean=list.get(0);
        if(bean.getType()==1){
            holder.tvStatus.setText(status[0]);
            holder.tvStatus.setTextColor(c2);
            holder.tvShow.setText("充值金额：");
        }else{
            holder.tvStatus.setText(status[bean.getStatus()]);
            holder.tvStatus.setTextColor(c1);
            holder.tvShow.setText("到账金额：");
        }
        Glide.with(mContext).load(bean.getUrl()).into(holder.ivCoin);
        holder.tvCoin.setText(bean.getCoinName().toUpperCase());
        holder.tvNum.setText(bean.getTotal()+"");
        holder.tvTime.setText(sdf.format(bean.getCreateTime()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView ivCoin;
        private TextView tvCoin;
        private TextView tvShow;
        private TextView tvNum;
        private TextView tvStatus;
        private TextView tvTime;

        public ViewHolder(View itemView) {
            super(itemView);
            ivCoin = itemView.findViewById(R.id.iv_coin);
            tvCoin = itemView.findViewById(R.id.tv_coin);
            tvShow = itemView.findViewById(R.id.tv_show);
            tvNum = itemView.findViewById(R.id.tv_num);
            tvStatus = itemView.findViewById(R.id.tv_status);
            tvTime = itemView.findViewById(R.id.tv_time);
        }
    }
}
